attachAndroidHardwareBufferRing

fun MapHandle.attachAndroidHardwareBufferRing(descriptor: AndroidHardwareBufferRingDescriptor, device: VulkanDeviceHandle? = null, options: RenderSessionAttachOptions): RenderSessionHandle

Creates a session that renders the map into a ring of Android hardware buffers that the library allocates.

Acquire each frame with RenderSessionHandle.acquireFrame(), and get its buffer with AcquiredFrameHandle.withAndroidHardwareBuffer(). RenderSessionHandle.resize() gives the ring new buffers of the new size.

A Vulkan build renders with device, or, when device is null, with a device that the library creates. An OpenGL build uses an EGL context on the default display, and device must be null. Attach with RenderDriverKind.CORE_WORKER.

To show the buffers through Android's UI, such as with Bitmap.wrapHardwareBuffer, attach without GpuSyncKindFlag.SYNC_FD in RenderSessionAttachOptions.producerSyncKinds, so that each frame finishes before you acquire it. Keep each frame acquired until the next one replaces it on screen, then release it with GpuSyncKind.CPU_COMPLETE. Give the ring 3 buffers, so the session can render while you hold two frames.

See mln_map_attach_android_hardware_buffer_ring in the C API reference.

Errors:

  • Status.UNSUPPORTED when Android is older than 8.0, API level 26, or when the graphics context can't render into hardware buffers: the Vulkan device lacks VK_ANDROID_external_memory_android_hardware_buffer, or the EGL display lacks EGL_ANDROID_get_native_client_buffer or EGL_ANDROID_image_native_buffer.

  • Status.NATIVE_ERROR when the library can't create its Vulkan device or initialize the default EGL display.